//制作链表 
class LinkNode {
    constructor(val, next) {
        this.val = val;
        this.next = next;
    }
}

// 删除
var removeElements = function (head, val) {
    const ret = new LinkNode(0, head);
    let cur = ret;
    while (cur.next) {
        if (cur.next.val == val) {
            cur.next = cur.next.next;
            continue;
        }
        cur = cur.next;
        // cur=cur.next实际是将cur引用的位置从当前节点移动到下一节点，
    }
    return ret.next;
}
// 增加
var addElements = function (newVal, val) {
    let newNode = new link(newVal);
    let curNode = this.head;    //找到要添加的节点
    while (curNode.next) {
        curNode = curNode.next;
    }
    curNode.next = newNode;
}
// 查找
var findElements = function (val) {
    let curNode = this.head;    //从头节点开始遍历
    while (curNode && curNode.val) {
        if (curNode.val == val) {
            return curNode;
        }
        curNode = curNode.next;
    }
    return null;
}
// 修改
var alterElements = function (NewVal, val) {
    let curNode = this.find(val);    //找到要修改的节点
    if (curNode) {
        curNode.val = newVal;
    }
    else {
        console.log("链表中不存在" + val + "元素");
    }
}